home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / spawnve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.1 KB  |  63 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  * $Header: spawnve.c,v 1.1 88/01/29 17:30:04 m68k Exp $
  6.  *
  7.  * $Log:    spawnve.c,v $
  8.  * Revision 1.1  88/01/29  17:30:04  m68k
  9.  * Initial revision
  10.  * 
  11.  */
  12. #include    <param.h>
  13. #include    <osbind.h>
  14.  
  15. static    char    cmd[NCARGS+1];
  16. static    char    env[1024];        /* this should be enough */
  17.  
  18. int
  19. spawnve(path, argv, envp)
  20.     char    *path;
  21.     char    **argv;
  22.     char    **envp;
  23. {
  24.     extern    int    errno;
  25.  
  26.     int        len = NCARGS;
  27.     char        *p;
  28.     char        *s;
  29.  
  30.     bzero(s = cmd, sizeof(cmd));
  31.     if (argv && *argv)
  32.         while (*++argv) {
  33.             for (p = *argv ; --len >= 0 && *p ; )
  34.                 *s++ = *p++;
  35.             if (len >= 0)
  36.                 *s++ = ' ';
  37.             else
  38.                 break;
  39.         }
  40.     if (envp && *envp) {
  41.         len = sizeof(env) - 2;
  42.         s = env;
  43.         while (*++argv) {
  44.             for (p = *envp ; --len >= 0 && *p ; )
  45.                 *s++ = *p++;
  46.             if (len >= 0)
  47.                 *s++ = '\0';
  48.             else
  49.                 break;
  50.         }
  51.         *s++ = '\0';
  52.         *s = '\0';
  53.     }
  54.  
  55.     if ((len = Pexec(PE_LOADGO, path, cmd, envp ? env : (char *) 0))
  56.         < 0)
  57.     {
  58.         errno = -len;
  59.         len = -1;
  60.     }
  61.     return len;
  62. }
  63.